﻿namespace Bll.Systems
{
    using Model.Systems;
    using System;
    using System.Collections;
    using System.Data;
    using WinFormSession;

    public class PopedomCheckWindows
    {
        public static string[] checkPopIsUse = null;
        public static string[] CheckPopName = null;
        public static ArrayList PopList = new ArrayList();

        public static void checkRolePopeDom()
        {
            ConfigEnt model = ConfigBll.GetModel(1);
            UserEnt ent2 = (UserEnt) WinformSession.GetSession()["user"];
            if ((model.IsUseMeUse == 0) && (ent2 != null))
            {
                DataTable list;
                string str = ent2.RoleId.ToString();
                if (str != "")
                {
                    list = RolePopedomBll.GetList("RoleId=" + str);
                    if (list.Rows.Count > 0)
                    {
                        string rolePopsValue = list.Rows[0]["PopedomValue"].ToString();
                        PopList.Clear();
                        FenJiePopeDom(rolePopsValue);
                    }
                }
                for (int i = 0; i < CheckPopName.Length; i++)
                {
                    list = PopdomValueBll.GetList("PopdomAction='" + CheckPopName[i] + "'");
                    if (list.Rows.Count > 0)
                    {
                        if (CheckUseRolePop(list.Rows[0]["PopdomId"].ToString()))
                        {
                            checkPopIsUse[i] = "1";
                        }
                        else
                        {
                            checkPopIsUse[i] = "0";
                        }
                    }
                }
            }
        }

        private static bool CheckUseRolePop(string PopId)
        {
            foreach (object obj2 in PopList)
            {
                PoplueEnt ent = (PoplueEnt) obj2;
                if (ent.PopId == PopId)
                {
                    return (ent.IsUsePop == "1");
                }
            }
            return false;
        }

        private static void FenJiePopeDom(string rolePopsValue)
        {
            string[] strArray = rolePopsValue.Split(new char[] { '|' });
            int length = 0;
            foreach (string str in strArray)
            {
                if (str != "")
                {
                    Exception exception;
                    string str2 = str;
                    PoplueEnt ent = new PoplueEnt();
                    try
                    {
                        length = str.IndexOf("$");
                        ent.PopId = str.Substring(0, length);
                        str2 = str2.Remove(0, length + 2);
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                    }
                    try
                    {
                        length = str2.IndexOf(")");
                        ent.IsUsePop = str2.Substring(0, length);
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                    }
                    PopList.Add(ent);
                }
            }
        }
    }
}

